/***
 * @file: 路由主文件
 * @author: xiaoyu
 * @Date: 2021-07-06 16:34:07
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import routerDemo from './demo/index'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    component: () => import(/* webpackChunkName: "group-user" */ '@/views/home.vue'),
    meta: {
      title: '首页'
    }
  },
  // {
  //   path: '/demo',
  //   name: 'demo',
  //   component: () => import(/* webpackChunkName: "demo" */ '@/views/demo/demo.vue'),
  //   meta: {
  //     title: 'demo演示'
  //   }
  // },
  ...routerDemo,
  {
    path: '/:pathMatch(.*)*',
    name: 'NotFound',
    component: () => import(/* webpackChunkName: "demo" */ '@/views/error/404.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 全局路有钩子
router.beforeEach((to, from) => {
  if (to.meta && to.meta.title) {
    document.title = <string>to.meta.title
  }
  return true
})

export default router
